<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0" />
    <title>美策平台</title>
    <link rel="icon" type="image/png" href="/img/icon.png">
    <link rel="stylesheet" type="text/css" href="datepicker/jquery-ui.min.css">
    <link rel="stylesheet" type="text/css" href="css/app.css">
    <link rel="stylesheet" type="text/css" href="css/news.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script src="datepicker/jquery-ui.min.js"></script>
    <script type="text/javascript" src="/pc/js/all.js"></script>
</head>
<body>
<!--
    创建：九哥
    页面：资讯主页面
    时间：2019-03-05
    更新：
-->





<!----------资讯主页面---------->
<div id="newsPage">
    <div id="newsTitle">
        <b>最新资讯</b>
    </div>
    <div style="height:40px;"></div>
    <div id="newsDetail">
        <div class="load">努力加载中...</div>
    </div>

    <!--底部菜单-->
    <div style="height:60px"></div>
    <div id="footer">
        <button id="toHomePage">
            <img src="images/home_01.png">
            <p>首页</p>
        </button>
        <button id="toNewsPage">
            <img src="images/news.png">
            <p>资讯</p>
        </button>
        <button id="toOrderPage">
            <img src="images/order_01.png">
            <p>订单</p>
        </button>
        <button id="toWorkPage" style="display:none;">
            <img src="images/icon_work.png">
            <p>工作</p>
        </button>
        <button id="toMessagePage">
            <img src="images/message_01.png">
            <p>消息</p>
        </button>
        <button id="toMysetPage">
            <img src="images/mine_01.png">
            <p>我的</p>
        </button>
    </div>
</div>
<!----------资讯主页面---------->





<!----------错误提示---------->
<div id="errMsg"></div>
<!----------错误提示---------->
</body>
<script type="text/javascript" src="js/app.js"></script>
<script type="text/javascript" src="js/newsPageChange.js"></script>
<!-- <script type="text/javascript" src="js/rem.js"></script> -->
<script type="text/javascript" src="js/news.js"></script>
<script>
    (function(){
        setFootBtn(); //员工主体，更换订单图标
        //getNewsList();
        getIndex(); //资讯主页数据
    })();
    /**
     * 资讯列表数据
     * */
    function getIndex(){
        var cache = cacheGet('newsList'); //资讯列表数据
        var p = '<p style="text-align:center;color:#888;">加载中...</p>';
        var h = '';
        if (cache && cache.length > 0) {
            h = getIndexStr(cache);
            $('#newsDetail').html(h);
        } else {
            $('#newsDetail').html(p);
        }
        var formData = {
            app_access:app_access
        };
        $.ajax({
            type:'post',
            url:getDomain() + 'index',
            data:formData,
            success:function(res){
                //console.log(res); return;
                if (res.code!=200) {
                    $('#newsDetail').html('<div class="load">没有资讯</div>');
                    //getErrMsg(res.msg,'');
                    console.log(res.msg);
                    return;
                }
                console.log(res.data);
                var data = res.data;
                h = getIndexStr(data);
                $('#newsDetail').html(h);
                //设置缓存
                cacheSet('newsList',data);
                getAppErrMsg('资讯列表已更新！','',0);
            },
            error:function(){
                console.log('操作失败！'); return;
            }
        });
    }
    //拼接资讯列表数据
    function getIndexStr(data){
        var i, h = '';
        for (i=0;i<data.length;i++) {
            h += '<div class="newslist">';
            h +=    '<div style="height:15px"></div>';
            h +=    '<div class="title">';
            h +=        '<div>';
            if (data[i].head=='') {
                h += '<span style="background-image:url(/h5/images/logo-di.png)"></span>';
            } else {
                h += '<span style="background-image:url('+data[i].head+')"></span>';
            }
            h +=        '</div>';
            h +=        '<div class="cname">'+data[i].uname+'</div>';
            h +=    '</div>';
            h +=    '<div class="detail">';
            h +=        '<p onclick="setShow('+data[i].id+')">'+data[i].intro+'</p>';
            h +=        '<p onclick="setShow('+data[i].id+')">';
            if (data[i].thumb=='') {
                h += '<span style="background-image:url(/h5/images/logo-di.png)"></span>';
            } else {
                h += '<span style="background-image:url('+data[i].thumb+')"></span>';
            }
//            h += '<span style="background-image:url('+data[i].thumb+')"></span>';
            h +=        '</p>';
            h +=        '<span onclick="setPraise('+data[i].id+')">';
            h +=            '<div class="zan">';
            h +=                '<div id="zanImg" style="float:left;">';
            h +=                    '<img src="/h5/images/zan.png" width="15">';
            h +=                '</div>';
            h +=            '</div>';
            h +=            '<div class="zanNum" id="zanNum" style="padding:2px 5px;font-size:12px;color:#888888;float:left;">'+data[i].praise+'</div>';
            h +=        '<span>';
            h +=        '<div style="height:30px"></div>';
            h +=    '</div>';
            h += '</div>';
        }
        return h;
    }
    /**
     * 地址前缀
     * */
    function getDomain(){
        return '/api/news/';
    }
</script>
</html>